#ifndef __VSFJEG_H_INCLUDED__
#define __VSFJEG_H_INCLUDED__

#include "component/3rd/jeg/nes.h"

#ifndef VSFJEG_CFG_DECODER_BUFSIZE
#define VSFJEG_CFG_DECODER_BUFSIZE		1024
#endif

#ifndef VSFJEG_CFG_FB_BUFNUM
#define VSFJEG_CFG_FB_BUFNUM			2
#endif

struct vsfjeg_decoder_t
{
	struct vsfav_adapter_t adapter;
	struct vsfav_stream_t outstream;
	struct vsf_mbufstream_t mbuf;
	uint8_t *buflist[2];
	uint8_t buffer[2][VSFJEG_CFG_DECODER_BUFSIZE];

	bool out_pend;
	uint32_t sync;
	uint8_t *ptr;
	uint32_t size;
	struct vsfsm_t sm;
};

struct vsfjeg_t
{
	struct
	{
		nes_t console;
		uint8_t controller[2];
		struct vsf_buffer_t rom;
	} nes;

	struct
	{
		struct vsfui_fb_t fb;
		uint8_t *buflist[VSFJEG_CFG_FB_BUFNUM];
		uint8_t buffer[VSFJEG_CFG_FB_BUFNUM][240 * 256];
		bool updating;

		struct vsfjeg_decoder_t decoder;

#ifdef VSFJEG_CFG_DEBUG
		uint32_t start_tick;
		uint32_t frame_cnt;
#endif
	} video;
	bool started;
};

void vsfjeg_init(struct vsfjeg_t *jeg);
void vsfjeg_poll(struct vsfjeg_t *jeg);

#endif		// __VSFJEG_H_INCLUDED__
